package edu.zac.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @Title
 * @Author Peihan.Zhang
 * @Email zhangpeihan@sjgtw.com
 * @Date 2021/10/22 21:34
 * @Versions 1.0
 */
public class PProxyFactory {

    public static  Object getProxy( final Object target){

        Proxy proxy = (Proxy) Proxy.newProxyInstance(target.getClass().getClassLoader(), target.getClass().getInterfaces(), new InvocationHandler() {
            Object result=null;
            @Override
            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {

                System.out.println("草泥马");
                result= method.invoke(target, args);
                System.out.println("完了");

                return result;
            }
        });
        return  proxy;
    }
}
